package com.flame.user.controller;

import com.flame.auth.core.annotation.HasAuth;
import com.flame.core.protocol.PageResult;
import com.flame.core.protocol.Result;
import com.flame.user.controller.vo.DataAuthVo;
import com.flame.user.entity.DataAuth;
import com.flame.user.service.DataAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * flame_data_auth 数据权限表
 *
 * @author 吴欣童
 * @since 2023-02-10 10:18:15
 */
@RestController
public class DataAuthController {

    @Autowired
    private DataAuthService dataAuthService;

    @HasAuth("auth")
    @PostMapping("/data/auth/page")
    public PageResult pageDataAuth(@RequestBody DataAuthVo dataAuthVo) {
        return PageResult.success(dataAuthService.pageDataAuth(dataAuthVo));
    }

    @HasAuth("auth:edit")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/data/auth/maintain")
    public Result addDataAuth(@RequestBody @Validated DataAuth dataAuth) {
        dataAuthService.maintainDataAuth(dataAuth);
        return Result.success();
    }

    @HasAuth("auth:edit")
    @Transactional(rollbackFor = Exception.class)
    @PostMapping("/data/auth/delete")
    public Result deleteDataAuth(@RequestBody @Validated DataAuth dataAuth) {
        dataAuthService.deleteDataAuth(dataAuth);
        return Result.success();
    }

}
